package home.my.base.util;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public class TypeUtil {
	
	//父类构造函数被调用时,从子类泛型注释中获取第n个参数Class
	public static Class<?> getClassType(Object obj){
		Class<?> c = null;
		try {
			Type[] types = null;
			Type t =  obj.getClass().getGenericSuperclass();
			if( t instanceof ParameterizedType ){
				types = ((ParameterizedType)t).getActualTypeArguments();
			}
			if (types!=null && types.length>0 && types[0] instanceof Class){
				c = (Class<?>) types[0];
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return c;
	}
}
